package com.yjs.ppjokedemo.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.yjs.ppjokedemo.bean.RecomProduct;
import com.yjs.ppjokedemo.databinding.ItemFindRecommendBinding;

public class RecomListAdapter extends ListAdapter<RecomProduct,RecomListAdapter.RecomViewHolder> {

    RecomInterface mRecomInterface;

    public RecomListAdapter(RecomInterface recomInterface){
        super(RecomProduct.itemCallback);
        this.mRecomInterface = recomInterface;
    }

    @Override
    public RecomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        ItemFindRecommendBinding itemFindRecommendBinding = ItemFindRecommendBinding.inflate(layoutInflater,parent,false);
        itemFindRecommendBinding.setRecomInterface(mRecomInterface);
        return new RecomViewHolder(itemFindRecommendBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull RecomViewHolder holder, int position) {
        RecomProduct recomProduct = getItem(position);
        holder.mItemFindRecommendBinding.setRecomproduct(recomProduct);
    }

    static class RecomViewHolder extends RecyclerView.ViewHolder{
        ItemFindRecommendBinding mItemFindRecommendBinding;

        public RecomViewHolder(ItemFindRecommendBinding itemFindRecommendBinding){
            super(itemFindRecommendBinding.getRoot());
            this.mItemFindRecommendBinding = itemFindRecommendBinding;
        }
    }

    public interface RecomInterface{

        void addLiked(RecomProduct recomProduct);
    }
}
